package com.aaa.springbootredis.service.impl;

import com.aaa.springbootredis.dao.UserDao;
import com.aaa.springbootredis.entity.User;
import com.aaa.springbootredis.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年12月07日10:10
 */
@Service
public class UserServiceImpl implements Userservice {
    @Autowired
    private UserDao userDao;

    @Autowired
    private RedisTemplate<String,Object> template;

    @Override
    @Cacheable(cacheNames="redis::user",key="#id")
    public User findById(Integer id) {
        User user = userDao.selectById(id);
        return user;
    }

    @Override
    @Cacheable(cacheNames="redis::user",key="#id")
    public Integer delete(Integer id) {
        int i = userDao.deleteById(id);
        return i;
    }

    @Override
    @Cacheable(cacheNames="redis::user",key="#id")
    public User save(User user) {
        userDao.insert(user);
        return user;
    }

    @Override
    @Cacheable(cacheNames="redis::user",key="#id")
    public User update(User user) {
        userDao.updateById(user);
       return user;
    }
}
